/*     */ package com.iris.egrant.utils.date;
/*     */ 
/*     */ import com.iris.egrant.utils.Assert;
/*     */ import com.iris.egrant.app.utils.IrisStringUtils;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Calendar;
/*     */ import java.util.Date;
/*     */ import java.util.GregorianCalendar;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import java.util.regex.Matcher;
/*     */ import java.util.regex.Pattern;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class DateUtils
/*     */ {
/*     */   public static Date now() {
/*  24 */     return (new GregorianCalendar()).getTime();
/*     */   }
/*     */   
/*     */   public static Date now(DateFormator pattern) {
/*  28 */     Date date = now();
/*  29 */     String str = toString(date, pattern);
/*  30 */     return toDate(str);
/*     */   }
/*     */   
/*     */   public static Date toDate(String time, DateFormator pattern) {
/*  34 */     Assert.notNull(time);
/*  35 */     Assert.notNull(pattern);
/*  36 */     return CalendarUtils.toCalendar(time, pattern).getTime();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static Date toDate(String time) {
/*  46 */     Assert.notNull(time);
/*  47 */     for (String key : defaultDateFormatMap.keySet()) {
/*  48 */       if (isDateFormat(time, key)) {
/*  49 */         return toDate(time, defaultDateFormatMap.get(key));
/*     */       }
/*     */     } 
/*  52 */     throw new RuntimeException("just support format : " + IrisStringUtils.collectionToDelimitedString(defaultDateFormatMap.values(), ",") + " - " + time);
/*     */   }
/*     */ 
/*     */   
/*     */   public static String toString(Date date, DateFormator pattern) {
/*  57 */     Assert.notNull(date);
/*  58 */     Assert.notNull(pattern);
/*  59 */     SimpleDateFormat sdf = new SimpleDateFormat(pattern.toString());
/*  60 */     return sdf.format(date);
/*     */   }
/*     */   
/*     */   public static String toString(Date date) {
/*  64 */     Assert.notNull(date);
/*  65 */     return toString(date, DateFormator.YEAR_MONTH_DAY_HH_MM_SS);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static int compare(Date d1, Date d2) {
/*  77 */     Assert.notNull(d1);
/*  78 */     Assert.notNull(d2);
/*     */     
/*  80 */     Calendar c1 = new GregorianCalendar();
/*  81 */     Calendar c2 = new GregorianCalendar();
/*  82 */     c1.setTime(d1);
/*  83 */     c2.setTime(d2);
/*     */     
/*  85 */     return c1.compareTo(c2);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static int compareDate(Date d1, Date d2) {
/*  97 */     Assert.notNull(d1);
/*  98 */     Assert.notNull(d2);
/*     */     
/* 100 */     d1 = toDate(toString(d1, DateFormator.YEAR_MONTH_DAY), DateFormator.YEAR_MONTH_DAY);
/* 101 */     d2 = toDate(toString(d2, DateFormator.YEAR_MONTH_DAY), DateFormator.YEAR_MONTH_DAY);
/* 102 */     Calendar c1 = new GregorianCalendar();
/* 103 */     Calendar c2 = new GregorianCalendar();
/* 104 */     c1.setTime(d1);
/* 105 */     c2.setTime(d2);
/*     */     
/* 107 */     return c1.compareTo(c2);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static Date beginTimeOfMonth(int year, int month) {
/* 118 */     Calendar first = new GregorianCalendar(year, month - 1, 1, 0, 0, 0);
/* 119 */     return first.getTime();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static Date endTimeOfMonth(int year, int month) {
/* 130 */     Calendar first = new GregorianCalendar(year, month, 1, 0, 0, 0);
/* 131 */     first.add(14, -1);
/* 132 */     return first.getTime();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static Date preYears(Date date, int preYears) {
/* 143 */     GregorianCalendar c1 = new GregorianCalendar();
/* 144 */     c1.setTime(date);
/* 145 */     GregorianCalendar cloneCalendar = (GregorianCalendar)c1.clone();
/* 146 */     cloneCalendar.add(1, -preYears);
/* 147 */     return cloneCalendar.getTime();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static Date nextYears(Date date, int nextYears) {
/* 158 */     GregorianCalendar c1 = new GregorianCalendar();
/* 159 */     c1.setTime(date);
/* 160 */     GregorianCalendar cloneCalendar = (GregorianCalendar)c1.clone();
/* 161 */     cloneCalendar.add(1, nextYears);
/* 162 */     return cloneCalendar.getTime();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static Date preDays(Date date, int preDays) {
/* 173 */     GregorianCalendar c1 = new GregorianCalendar();
/* 174 */     c1.setTime(date);
/* 175 */     GregorianCalendar cloneCalendar = (GregorianCalendar)c1.clone();
/* 176 */     cloneCalendar.add(5, -preDays);
/* 177 */     return cloneCalendar.getTime();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static Date nextDays(Date date, int nextDays) {
/* 188 */     GregorianCalendar c1 = new GregorianCalendar();
/* 189 */     c1.setTime(date);
/* 190 */     GregorianCalendar cloneCalendar = (GregorianCalendar)c1.clone();
/* 191 */     cloneCalendar.add(5, nextDays);
/* 192 */     return cloneCalendar.getTime();
/*     */   }
/*     */   
/*     */   public static Date nextMonths(Date date, int nextMonth) {
/* 196 */     GregorianCalendar c1 = new GregorianCalendar();
/* 197 */     c1.setTime(date);
/* 198 */     GregorianCalendar cloneCalendar = (GregorianCalendar)c1.clone();
/* 199 */     cloneCalendar.add(2, nextMonth);
/* 200 */     return cloneCalendar.getTime();
/*     */   }
/*     */   
/*     */   public static Date preMonths(Date date, int preMonth) {
/* 204 */     GregorianCalendar c1 = new GregorianCalendar();
/* 205 */     c1.setTime(date);
/* 206 */     GregorianCalendar cloneCalendar = (GregorianCalendar)c1.clone();
/* 207 */     cloneCalendar.add(2, -preMonth);
/* 208 */     return cloneCalendar.getTime();
/*     */   }
/*     */   
/*     */   public static long getDiffMillis(Date d1, Date d2) {
/* 212 */     Assert.notNull(d1);
/* 213 */     Assert.notNull(d2);
/*     */     
/* 215 */     long diff = d1.getTime() - d2.getTime();
/*     */     
/* 217 */     return diff;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static long dayDiff(Date d1, Date d2) {
/* 229 */     Assert.notNull(d1);
/* 230 */     Assert.notNull(d2);
/*     */     
/* 232 */     Calendar c1 = new GregorianCalendar();
/* 233 */     Calendar c2 = new GregorianCalendar();
/*     */     
/* 235 */     c1.setTime(d1);
/* 236 */     c2.setTime(d2);
/*     */     
/* 238 */     long diffDays = CalendarUtils.getDiffDays(c1, c2);
/*     */     
/* 240 */     return diffDays;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static long diffMillis(Date d1, Date d2) {
/* 252 */     Assert.notNull(d1);
/* 253 */     Assert.notNull(d2);
/*     */     
/* 255 */     Calendar c1 = new GregorianCalendar();
/* 256 */     Calendar c2 = new GregorianCalendar();
/*     */     
/* 258 */     c1.setTime(d1);
/* 259 */     c2.setTime(d2);
/*     */     
/* 261 */     long diffDays = CalendarUtils.getDiffMillis(c1, c2);
/*     */     
/* 263 */     return diffDays;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static String getDiffs(Date d1, Date d2) {
/* 274 */     long diffMillis = getDiffMillis(d1, d2);
/* 275 */     long diffHours = diffMillis / 3600000L;
/* 276 */     long diffMinutes = diffMillis / 60000L % 60L;
/* 277 */     long diffSeconds = diffMillis / 1000L % 60L;
/* 278 */     diffHours = Math.abs(diffHours);
/* 279 */     diffMinutes = Math.abs(diffMinutes);
/* 280 */     diffSeconds = Math.abs(diffSeconds);
/* 281 */     StringBuffer temp = new StringBuffer();
/* 282 */     temp.append((diffHours < 10L) ? ("0" + diffHours) : Long.valueOf(diffHours));
/* 283 */     temp.append(":");
/* 284 */     temp.append((diffMinutes < 10L) ? ("0" + diffMinutes) : Long.valueOf(diffMinutes));
/* 285 */     temp.append(":");
/* 286 */     temp.append((diffSeconds < 10L) ? ("0" + diffSeconds) : Long.valueOf(diffSeconds));
/* 287 */     return temp.toString();
/*     */   }
/*     */   
/*     */   public static boolean isDateFormat(String date) {
/* 291 */     Assert.notNull(date);
/* 292 */     for (String key : defaultDateFormatMap.keySet()) {
/* 293 */       if (isDateFormat(date, key)) {
/* 294 */         return true;
/*     */       }
/*     */     } 
/* 297 */     return false;
/*     */   }
/*     */   
/*     */   public static boolean isDateFormat(String date, String format) {
/* 301 */     Assert.notNull(date);
/* 302 */     return IrisStringUtils.isDefinedPattern(date, format);
/*     */   }
/*     */   
/*     */   public static Date getNowDate() {
/* 306 */     Date now = new Date();
/* 307 */     return toDate(toString(now, DateFormator.YEAR_MONTH_DAY), DateFormator.YEAR_MONTH_DAY);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static int getYear(Date d) {
/* 317 */     Assert.notNull(d);
/* 318 */     String dateStr = toString(d, DateFormator.YEAR_MONTH);
/* 319 */     return Integer.parseInt(dateStr.split(DateFormator.SPLIT_CHAR.toString())[0]);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static int getMonth(Date d) {
/* 329 */     Assert.notNull(d);
/* 330 */     String dateStr = toString(d, DateFormator.YEAR_MONTH);
/* 331 */     return Integer.parseInt(dateStr.split(DateFormator.SPLIT_CHAR.toString())[1]);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static int getDay(Date d) {
/* 341 */     Assert.notNull(d);
/* 342 */     String dateStr = toString(d, DateFormator.YEAR_MONTH_DAY);
/* 343 */     return Integer.parseInt(dateStr.split(DateFormator.SPLIT_CHAR.toString())[2]);
/*     */   }
/*     */   
/*     */   public static boolean isEnDateFormat(String str) {
/* 347 */     String rex = "((((02|2)\\/29)\\/(19|20)(([02468][048])|([13579][26])))|((((0?[1-9])|(1[0-2]))\\/((0?[1-9])|(1\\d)|(2[0-8])))|((((0?[13578])|(1[02]))\\/31)|(((0?[1,3-9])|(1[0-2]))\\/(29|30))))\\/((20[0-9][0-9])|(19[0-9][0-9])|(18[0-9][0-9])))";
/* 348 */     Pattern regex = Pattern.compile(rex);
/* 349 */     Matcher matcher = regex.matcher(str);
/* 350 */     boolean isMatched = matcher.matches();
/* 351 */     return isMatched;
/*     */   }
/*     */   
/* 354 */   private static Map<String, DateFormator> defaultDateFormatMap = new HashMap<String, DateFormator>();
/*     */   static {
/* 356 */     defaultDateFormatMap.put("[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}", DateFormator.YEAR_MONTH_DAY);
/* 357 */     defaultDateFormatMap.put("[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}", DateFormator.YEAR_MONTH_DAY_EU);
/* 358 */     defaultDateFormatMap.put("[0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}", DateFormator.YEAR_MONTH_DAY_HH_MM_SS);
/*     */     
/* 360 */     defaultDateFormatMap.put("[0-9]{4}/[0-9]{1,2}/[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}", DateFormator.YEAR_MONTH_DAY_H_M_S_EU);
/*     */     
/* 362 */     defaultDateFormatMap.put("[0-9]{4}-[0-9]{1,2}", DateFormator.YEAR_MONTH);
/* 363 */     defaultDateFormatMap.put("[0-9]{4}/[0-9]{1,2}", DateFormator.YEAR_MONTH_EU);
/* 364 */     defaultDateFormatMap.put("((((02|2)/29)/(19|20)(([02468][048])|([13579][26])))|((((0?[1-9])|(1[0-2]))/((0?[1-9])|(1\\d)|(2[0-8])))|((((0?[13578])|(1[02]))/31)|(((0?[1,3-9])|(1[0-2]))/(29|30))))/((20[0-9][0-9])|(19[0-9][0-9])|(18[0-9][0-9])))", DateFormator.MONTH_DAY_YEAR_EU);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static String getCurrentYear() {
/* 374 */     Calendar cal = Calendar.getInstance();
/* 375 */     return String.valueOf(cal.get(1));
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static String getYear(String currentYear, int years) {
/* 385 */     Calendar cal = Calendar.getInstance();
/* 386 */     if (StringUtils.isNotBlank(currentYear)) {
/* 387 */       cal.set(1, Integer.parseInt(currentYear));
/*     */     }
/* 389 */     cal.add(1, years);
/* 390 */     return String.valueOf(cal.get(1));
/*     */   }
/*     */ 
/*     */   
/*     */   public static boolean belongCalendar(Date now, Date begin, Date end) {
/* 395 */     Calendar nowTime = Calendar.getInstance();
/* 396 */     Calendar beginTime = Calendar.getInstance();
/* 397 */     Calendar endTime = Calendar.getInstance();
/* 398 */     nowTime.setTime(now);
/* 399 */     beginTime.setTime(begin);
/* 400 */     endTime.setTime(end);
/* 401 */     if (nowTime.after(beginTime) && nowTime.before(endTime)) {
/* 402 */       return true;
/*     */     }
/* 404 */     return false;
/*     */   }
/*     */ 
/*     */   
/*     */   public static Date nextHoures(Date date, int nextHour) {
/* 409 */     GregorianCalendar c1 = new GregorianCalendar();
/* 410 */     c1.setTime(date);
/* 411 */     GregorianCalendar cloneCalendar = (GregorianCalendar)c1.clone();
/* 412 */     cloneCalendar.add(11, nextHour);
/* 413 */     return cloneCalendar.getTime();
/*     */   }
/*     */ }


/* Location:              D:\文件kjt\WEB-INF\lib\egrant-core-2.2.20240205.1659.jar!\com\iris\egran\\utils\date\DateUtils.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */